import java.util.*;
public class Main{
	
	public static void main(String[]args)throws Exception {
	    final Object obj = new Object();
	    Thread t1 = new Thread() {
	        public void run() {
	            synchronized (obj) {
	                obj.notifyAll();
					System.out.println("Thread 1 wake up.");
	            }
	        }
	    };
	    
	    Thread t2 = new Thread() {
	        public void run() {
	            synchronized (obj) {
	                try {
						obj.wait(); 
						System.out.println("Thread 2 sent notify.");
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
	               
	            }
	        }
	    };
	    t2.start();
	    Thread.sleep(1000);//We assume thread 1 must start up within 1 sec.
	    t1.start();
	}
}